#! -*- coding: utf-8 -*-
import os
import datetime
from io import BytesIO

import jwt
import pandas as pd
from sqlalchemy import func, desc, or_, and_
from flask import request, jsonify, current_app, send_file, send_from_directory

from config import base_config, log_config
from .models import (
    CdcAccessInfo,
    CdcUserInfo,
    CdcBaseInfo,
    CdcResumeInfo,
    CdcActivityInfo,
    CdcBackgroundInfo,
    CdcInternshipInfo,
    CdcOfferInfo,
    CdcKeyInfo,
    CdcGraduateInfo,
    CdcDailyInfo,
    CdcBoxGraduateRegisteReport,
    CdcBoxProvinceSystemReport,
    CdcBoxParentsContacted,
    CdcBoxDifficultyType,
    CdcBoxApecialAttention,
    CdcBoxOfferState,
    CdcBoxEntranceYear,
    CdcBoxProjectType,
    CdcBoxChineseLevel,
    CdcBoxOfferType,
    CdcBoxGraduatePlan,
    CdcSchoolProgramArea,
    CdcBoxMajor,
    CdcBoxArea,
    CdcBoxExportOptions,
    CdcBoxImportOptions,
    CdcBoxRecordType,
    CdcBoxEnrollmentType,
    CdcBoxEnrollmentStatus,
    CdcBoxAdvisor
)


class CdcCareer:

    def __init__(self):
        self.session = current_app.config["ENGINES"]["sme_cdc_career"]
        self.resume_path = "/mnt/nas-ex/team_data/cdc/cdc_career/resume_data"
        self.import_template_path = "/home/master/ID-object-204/object/templates/ID_sme/cdc_career"
        self.logger = log_config.generate_logger(
            base_config.SME_CDC_CAREER["INFO_LOG_PATH"], 
            base_config.SME_CDC_CAREER["WARN_LOG_PATH"], 
            base_config.SME_CDC_CAREER["ERROR_LOG_PATH"]
        )

    def login(self):
        try:
            f_username = request.json.get("username", str())
            f_password = request.json.get("password", str())
            self.logger.info(f"[{request.request_id}] username: {f_username}, password: {f_password}")
            query = self.session.query(CdcUserInfo).filter(CdcUserInfo.f_username == f_username, CdcUserInfo.f_password == f_password)
            obj = query.first()
            if not obj:
                self.logger.warning(f"[{request.request_id}] 用户名或密码错误")
                return jsonify({"code": 400, "msg": "用户名或密码错误", "data": {}})
            obj.f_token = jwt.encode(
                {
                    "username": obj.f_username,
                    "password": obj.f_password,
                    "exp": datetime.datetime.now() + datetime.timedelta(hours=24),
                },
                base_config.SECRET_KEY,
                algorithm="HS256",
            )
            obj.f_update = datetime.datetime.now()
            self.session.commit()
            self.logger.info(f"[{request.request_id}] 登录成功")
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "uid": str(obj.id),
                        "token": str(obj.f_token),
                        "access_id": str(obj.f_access_id),
                        "access_name": str(obj.f_access_name),
                        "display_name": str(obj.f_display_name),
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def logout(self):
        try:
            f_uid = request.json.get("uid", str())
            f_token = request.json.get("token", str())
            query = self.session.query(CdcUserInfo).filter(CdcUserInfo.id == f_uid, CdcUserInfo.f_token == f_token)
            obj = query.first()
            obj.f_token = "N/A"
            obj.f_update = datetime.datetime.now()
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            f_name = request.json.get("name", str())
            f_major = request.json.get("major", str())
            f_state = request.json.get("state", str())
            f_approach = request.json.get("approach", str())
            f_difficulty = request.json.get("difficulty", str())
            f_partner = request.json.get("partner", str())
            f_graduation_year = request.json.get("graduation_year", int())
            f_dict = {
                "f_sid": f_sid,
                "f_name": f_name,
                "f_major": f_major,
                "f_status": f_state,
                "f_enrollment_type": f_approach,
                "f_advisor": f_partner,
                "f_graduation_year": f_graduation_year
            }
            non_empty_fields = { key:value for key,value in f_dict.items() if isinstance(value, str) and value.strip() != "" }
            query = self.session.query(
                CdcBaseInfo, CdcKeyInfo, CdcBackgroundInfo
            ).join(
                CdcBackgroundInfo, CdcBackgroundInfo.f_sid == CdcBaseInfo.f_sid
            ).join(
                CdcKeyInfo, CdcKeyInfo.f_sid == CdcBaseInfo.f_sid
            )
            for key, value in non_empty_fields.items():
                query = query.filter(getattr(CdcBaseInfo, key).like(f"%{value}%"))
            if f_difficulty == "是":
                query = query.filter(and_(
                    CdcKeyInfo.f_difficulty_type.isnot(None),
                    CdcKeyInfo.f_difficulty_type != "",
                    CdcKeyInfo.f_difficulty_type != "N/A",
                ))
            if f_difficulty == "否":
                query = query.filter(or_(
                    CdcKeyInfo.f_difficulty_type.is_(None),
                    CdcKeyInfo.f_difficulty_type == "",
                    CdcKeyInfo.f_difficulty_type == "N/A",
                ))
            total = query.count()
            query = query.limit(int(f_limit)).offset((int(f_page) - 1) * int(f_limit))
            objs = query.all()
            res_data = list()
            _seq = 0
            for obj in objs:
                _seq += 1
                res_data.append({
                    "seq": str(_seq),
                    "record_id": str(obj.CdcBaseInfo.id),
                    "sid": str(obj.CdcBaseInfo.f_sid),
                    "name": str(obj.CdcBaseInfo.f_name),
                    "major": str(obj.CdcBaseInfo.f_major),
                    "approach": str(obj.CdcBaseInfo.f_academy),
                    "graduation_year": str(obj.CdcBaseInfo.f_graduation_pre_year),
                    "graduate_plan": str(obj.CdcBackgroundInfo.f_graduate_plan),
                    "cgpa": str(obj.CdcBaseInfo.f_gpa),
                    "phone": str(obj.CdcBaseInfo.f_phone),
                    "partner": str(obj.CdcBaseInfo.f_advisor),
                    "is_difficulty": "Y" if obj.CdcKeyInfo.f_difficulty_type not in ["", "N/A"] else "N",
                    "is_offer": "Y" if self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == CdcBaseInfo.f_sid).count() else "N"
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res_data
                    }
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_upload(self):
        try:
            pass
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_template_download(self):
        try:
            return send_from_directory(
                os.path.join(current_app.root_path, "object/templates/ID_sme/cdc_career"),
                "基础信息-模板.xlsx",
                as_attachment=True,
                download_name="BaseTemplate.xlsx"
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_download(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_name = request.json.get("name", str())
            f_college = request.json.get("college", str())
            f_major = request.json.get("major", str())
            f_grade = request.json.get("grade", str())
            f_graduation_pre = request.json.get("graduation_pre", str())
            f_graduation_year = request.json.get("graduation_year", str())
            f_phone = request.json.get("phone", str())
            f_email = request.json.get("email", str())
            f_state = request.json.get("state", str())
            f_cgpa = request.json.get("cgpa", str())
            f_dict = {
                "f_sid": f_sid,
                "f_name": f_name,
                "f_college": f_college,
                "f_major": f_major,
                "f_grade": f_grade,
                "f_graduation_pre": func.from_unixtime(f_graduation_pre),
                "f_graduation_year": f_graduation_year,
                "f_phone": f_phone,
                "f_email": f_email,
                "f_state": f_state,
                "f_cgpa": f_cgpa,
            }
            non_empty_fields = { key:value for key,value in f_dict.items() if isinstance(value, str) and value.strip() != "" }
            query = self.session.query(CdcBaseInfo).filter_by(**non_empty_fields)
            objs = query.all()
            res_data = list()
            _seq = 0
            for obj in objs:
                _seq += 1
                res_data.append({
                    "seq": str(_seq),
                    "record_id": str(obj.id),
                    "sid": str(obj.f_sid),
                    "name": str(obj.f_name),
                    "college": str(obj.f_college),
                    "major": str(obj.f_major),
                    "grade": str(obj.f_grade),
                    "graduation_pre": str(int(obj.f_graduation_pre.timestamp())) if obj.f_graduation_pre else "",
                    "graduation_year": str(obj.f_graduation_year),
                    "phone": str(obj.f_phone),
                    "email": str(obj.f_email),
                    "academic_advisor": str(obj.f_academic_advisor),
                    "academic_advisor_phone": str(obj.f_academic_advisor_phone),
                    "state": str(obj.f_state),
                    "emergency_contact": str(obj.f_emergency_contact),
                    "emergency_contact_phone": str(obj.f_emergency_contact_phone),
                    "cgpa": str(obj.f_cgpa),
                    "credit": str(obj.f_credit),
                    "approach": str(obj.f_approach),
                    "warn_info": str(obj.f_warn_info),
                })
            df = pd.DataFrame(res_data)
            output = BytesIO()
            with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
                df.to_excel(writer, sheet_name="Download", index=False)
            output.seek(0)
            return send_file(output, as_attachment=True, mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", download_name="Export.xlsx")
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_add(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_name = request.json.get("name", str())
            f_college = request.json.get("college", str())
            f_major = request.json.get("major", str())
            f_grade = request.json.get("grade", str())
            f_graduate_pre = request.json.get("graduation_pre", str())
            f_graduation_year = request.json.get("graduation_year", str())
            f_phone = request.json.get("phone", str())
            f_email = request.json.get("email", str())
            f_academic_advisor = request.json.get("academic_advisor", str())
            f_academic_advisor_phone = request.json.get("academic_advisor_phone", str())
            f_state = request.json.get("state", str())
            f_emergency_contact = request.json.get("emergency_contact", str())
            f_emergency_contact_phone = request.json.get("emergency_contact_phone", str())
            f_cgpa = request.json.get("cgpa", str())
            f_credit = request.json.get("credit", str())
            f_approach = request.json.get("approach", str())
            f_warn_info = request.json.get("warn_info", str())
            query = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid)
            obj = query.first()
            if obj:
                return jsonify({"code": 400, "msg": "学号已存在", "data": {}})
            base_obj = CdcBaseInfo(
                f_sid=f_sid,
                f_name=f_name,
                f_college=f_college,
                f_major=f_major,
                f_grade=f_grade,
                f_graduation_pre=func.from_unixtime(f_graduate_pre),
                f_graduation_year=f_graduation_year,
                f_phone=f_phone,
                f_email=f_email,
                f_academic_advisor=f_academic_advisor,
                f_academic_advisor_phone=f_academic_advisor_phone,
                f_state=f_state,
                f_emergency_contact=f_emergency_contact,
                f_emergency_contact_phone=f_emergency_contact_phone,
                f_cgpa=f_cgpa,
                f_credit=f_credit,
                f_approach=f_approach,
                f_warn_info=f_warn_info,
            )
            self.session.add(base_obj)
            self.session.commit()
            self.session.flush()
            base_id = base_obj.id
            background_obj = CdcBackgroundInfo(
                f_sid=f_sid,
                f_graduate_plan="N/A",
                f_internship_count="N/A",
                f_internship_company="N/A",
                f_internship_position="N/A",
                f_internship_location="N/A",
                f_consult_count="N/A",
                f_activity_count="N/A",
                f_activity_type="N/A",
                f_activity_name="N/A",
                f_activity_time="N/A",
                f_target_industry="N/A",
                f_target_position="N/A",
                f_target_location="N/A",
                f_target_area="N/A",
                f_target_program="N/A",
                f_ielts="N/A",
                f_toefl="N/A",
                f_gre="N/A",
                f_gmat="N/A",
                f_chinese_level="N/A",
                f_sid_id=base_id
            )
            self.session.add(background_obj)
            self.session.commit()
            activity_obj = CdcActivityInfo(
                f_sid=base_obj.f_sid,
                f_activity_time=datetime.datetime.now(),
                f_activity_type="N/A",
                f_activity_name="N/A",
                f_remark="N/A",
                f_sid_id=base_id
            )
            self.session.add(activity_obj)
            self.session.commit()
            internship_obj = CdcInternshipInfo(
                f_sid = f_sid,
                f_start_time = datetime.datetime.now(),
                f_end_time = datetime.datetime.now(),
                f_company = "N/A",
                f_position = "N/A",
                f_location = "N/A",
                f_sid_id = base_id
            )
            self.session.add(internship_obj)
            self.session.commit()
            offer_obj = CdcOfferInfo(
                f_sid = f_sid,
                f_offer_type = "N/A",
                f_offer_area = "N/A",
                f_company_college_name = "N/A",
                f_position_project_name = "N/A",
                f_entrance_date = datetime.datetime.now(),
                f_industry_name = "N/A",
                f_salary_month = "N/A",
                f_salary_year = "N/A",
                f_accept_status = "N/A",
                f_remark = "N/A",
                f_sid_id = base_id
            )
            self.session.add(offer_obj)
            self.session.commit()
            key_obj = CdcKeyInfo(
                f_sid = f_sid,
                f_apecial_attention = "N/A",
                f_difficulty_type = "N/A",
                f_support_need = "N/A",
                f_support_info = "N/A",
                f_parents_contacted = "N/A",
                f_sid_id = base_id
            )
            self.session.add(key_obj)
            self.session.commit()
            graduate_obj = CdcGraduateInfo(
                f_sid = f_sid,
                f_province_system_report = "N/A",
                f_graduate_registe_report = "N/A",
                f_sid_id = base_id
            )
            self.session.add(graduate_obj)
            self.session.commit()
            daily_obj = CdcDailyInfo(
                f_sid = f_sid,
                f_owner = "N/A",
                f_type = "N/A",
                f_time = datetime.datetime.now(),
                f_detail = "N/A",
                f_sid_id = base_id
            )
            self.session.add(daily_obj)
            self.session.commit()

            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "sid": f_sid,
                        "record_id": base_id,
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def main_delete(self):
        try:
            # TODO: 待实现
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})
    
    def main_major_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_query_key = request.json.get("query_key", str())
            query = self.session.query(CdcBoxMajor).filter(CdcBoxMajor.f_value.ilike(f'%{f_query_key}%'))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            base_info, background_info, offer_info, key_info, graduate_info, daily_info = dict(), dict(), dict(), dict(), dict(), dict()
            query = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.id == f_sid)
            obj = query.first()
            if obj is not None:
                base_info = {
                    "sid": str(obj.f_sid),
                    "base_info_id": str(obj.id),
                    "name": str(obj.f_name),
                    "college": str(obj.f_college),
                    "major": str(obj.f_major),
                    "grade": str(obj.f_grade),
                    "graduation_pre": str(int(obj.f_graduation_pre.timestamp())) if obj.f_graduation_pre else "",
                    "graduation_year": str(obj.f_graduation_year),
                    "phone": str(obj.f_phone),
                    "email": str(obj.f_email),
                    "academic_advisor": str(obj.f_academic_advisor),
                    "academic_advisor_phone": str(obj.f_academic_advisor_phone),
                    "state": str(obj.f_state),
                    "emergency_contact": str(obj.f_emergency_contact),
                    "emergency_contact_phone": str(obj.f_emergency_contact_phone),
                    "cgpa": str(obj.f_cgpa),
                    "credit": str(obj.f_credit),
                    "approach": str(obj.f_approach),
                    "warn_info": str(obj.f_warn_info),
                    "partner": str(obj.f_partner),
                }
            query = self.session.query(CdcBackgroundInfo).filter(CdcBackgroundInfo.f_sid == f_sid)
            obj = query.first()
            if obj is not None:
                background_info = {
                    "sid": str(obj.f_sid),
                    "background_info_id": str(obj.id),
                    "graduate_plan": str(obj.f_graduate_plan),
                    "internship_count": str(obj.f_internship_count),
                    "internship_company": str(obj.f_internship_company),
                    "internship_position": str(obj.f_internship_position),
                    "internship_location": str(obj.f_internship_location),
                    "resume_id": str(obj.f_resume_id),
                    "consult_count": str(obj.f_consult_count),
                    "activity_count": str(obj.f_activity_count),
                    "activity_type": str(obj.f_activity_type),
                    "activity_name": str(obj.f_activity_name),
                    "activity_time:": str(int(obj.f_activity_time.timestamp())) if obj.f_activity_time else "",
                    "target_industry": str(obj.f_target_industry),
                    "target_position": str(obj.f_target_position),
                    "target_location": str(obj.f_target_location),
                    "target_area": str(obj.f_target_area),
                    "target_program": str(obj.f_target_program),
                    "ielts": str(obj.f_ielts),
                    "toefl": str(obj.f_toefl),
                    "gre": str(obj.f_gre),
                    "gmat": str(obj.f_gmat),
                    "chinese_level": str(obj.f_chinese_level),
                }
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid)
            obj = query.first()
            if obj is not None:
                offer_info = {
                    "sid": str(obj.f_sid),
                    "offer_info_id": str(obj.id),
                    "offer_state": str(obj.f_offer_state),
                    "offer_area": str(obj.f_offer_area),
                    "college_name": str(obj.f_college_name),
                    "project_name": str(obj.f_project_name),
                    "project_type": str(obj.f_project_type),
                    "company_name": str(obj.f_company_name),
                    "position": str(obj.f_position),
                    "salary_month": str(obj.f_salary_month),
                    "salary_year": str(obj.f_salary_year),
                    "entrance_time": str(int(obj.f_entrance_time.timestamp())) if obj.f_entrance_time else "",
                    "entrance_year": str(obj.f_entrance_year),
                    "state": str(obj.f_state),
                }
            query = self.session.query(CdcKeyInfo).filter(CdcKeyInfo.f_sid == f_sid)
            obj = query.first()
            if obj is not None:
                key_info = {
                    "sid": str(obj.f_sid),
                    "key_info_id": str(obj.id),
                    "apecial_attention": str(obj.f_apecial_attention),
                    "difficulty_type": str(obj.f_difficulty_type),
                    "support_need": str(obj.f_support_need),
                    "support_info": str(obj.f_support_info),
                    "parents_contacted": str(obj.f_parents_contacted),
                }
            query = self.session.query(CdcGraduateInfo).filter(CdcGraduateInfo.f_sid == f_sid)
            obj = query.first()
            if obj is not None:
                graduate_info = {
                    "sid": str(obj.f_sid),
                    "graduate_info_id": str(obj.id),
                    "province_system_report": str(obj.f_province_system_report),
                    "graduate_registe_report": str(obj.f_graduate_registe_report),
                }
            query = self.session.query(CdcDailyInfo).filter(CdcDailyInfo.f_sid == f_sid)
            obj = query.first()
            if obj is not None:
                daily_info = {
                    "sid": str(obj.f_sid),
                    "university_recommend": str(obj.f_university_recommend),
                }
            
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "base_info": base_info,
                        "background_info": background_info,
                        "offer_info": offer_info,
                        "key_info": key_info,
                        "graduate_info": graduate_info,
                        "daily_info": daily_info,
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_base_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_base_info_id = request.json.get("base_info_id", str())
            query = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid)
            obj = query.first()
            res = dict()
            res["base_info_id"] = str(obj.id)
            res["sid"] = str(obj.f_sid)
            res["name"] = str(obj.f_name)
            res["major"] = str(obj.f_major)
            res["grade"] = str(obj.f_grade)
            res["phone"] = str(obj.f_phone)
            res["email"] = str(obj.f_email)
            res["warn_info"] = str(obj.f_warn_info)
            res["gender"] = str(obj.f_gender)
            res["academy"] = str(obj.f_academy)
            res["cgpa"] = str(obj.f_gpa)
            res["status"] = str(obj.f_status)
            res["enrollment_type"] = str(obj.f_enrollment_type)
            res["credit_status"] = str(obj.f_credit_status)
            res["advisor"] = str(obj.f_advisor)
            res["graduation_pre_term"] = str(obj.f_graduation_pre_term)
            res["graduation_pre_year"] = str(int(obj.f_graduation_pre_year.timestamp()))
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_base_info_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_base_info_id = request.json.get("base_info_id", str())
            f_name = request.json.get("name", str())
            f_major = request.json.get("major", str())
            f_grade = request.json.get("grade", str())
            f_phone = request.json.get("phone", str())
            f_email = request.json.get("email", str())
            f_warn_info = request.json.get("warn_info", str())
            f_gender = request.json.get("gender", str())
            f_academy = request.json.get("academy", str())
            f_gpa = request.json.get("cgpa", str())
            f_status = request.json.get("status", str())
            f_enrollment_type = request.json.get("enrollment_type", str())
            f_credit_status = request.json.get("credit_status", str())
            f_advisor = request.json.get("advisor", str())
            f_graduation_pre_term = request.json.get("graduation_pre_term", str())
            f_graduation_pre_year = request.json.get("graduation_pre_year", int())
            query = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid, CdcBaseInfo.id == f_base_info_id)
            obj = query.first()
            obj.f_name = f_name
            obj.f_major = f_major
            obj.f_grade = f_grade
            obj.f_phone = f_phone
            obj.f_email = f_email
            obj.f_warn_info = f_warn_info
            obj.f_gender = f_gender
            obj.f_academy = f_academy
            obj.f_gpa = f_gpa
            obj.f_status = f_status
            obj.f_enrollment_type = f_enrollment_type
            obj.f_credit_status = f_credit_status
            obj.f_advisor = f_advisor
            obj.f_graduation_pre_term = f_graduation_pre_term
            obj.f_graduation_pre_year = func.from_unixtime(f_graduation_pre_year)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_base_info_import(self):
        try:
            f_uid = request.form.get("uid", str())
            f_sid = request.form.get("sid", str())
            f_record_id = request.form.get("record_id", str())
            if "file" not in request.files:
                return jsonify({"code": 400, "msg": "未上传文件", "data": dict()})
            file = request.files["file"]
            if file.filename == "" or not file.filename.endswith(".xlsx"):
                return jsonify({"code": 400, "msg": "请选择有效的 XLSX 文件", "data": dict()})
            df = pd.read_excel(file)
            for index, row in df.iterrows():
                if index < 1:
                    continue
                f_sid = row.get("学号", "")
                f_name = row.get("姓名", "")
                f_gender = row.get("性别", "")
                f_academy = row.get("书院", "")
                f_major = row.get("专业名称", "")
                f_gpa = row.get("综合GPA", "")
                f_grade = row.get("年级", "")
                f_graduation_pre = row.get("预毕业学期", "")
                f_graduation_year = row.get("毕业年份", "")
                f_phone = row.get("联系方式", "")
                f_email = row.get("邮箱", "")
                f_status = row.get("学籍状态", "")
                f_enrollment_type = row.get("招生类型", "")
                f_credit_status = row.get("修分情况", "")
                f_warn_info = row.get("预警信息", "")
                f_advisor = row.get("顾问", "")
                f_graduation_plan = row.get("毕业计划", "")
                f_employment_area = row.get("意向就业地区", "")
                f_employment_industry = row.get("意向就业行业", "")
                f_employment_position = row.get("意向就业岗位", "")
                f_intend_area = row.get("意向升学地区", "")
                f_intend_school = row.get("意向升学院校", "")
                f_intend_field = row.get("意向升学领域", "")
                f_gre_gmat = row.get("GRE/GMAT", "")
                f_ielts_toefl = row.get("雅思/托福", "")
                f_special_student = row.get("特需生", "")
                f_difficulty_type = row.get("困难类型", "")
                f_cross_sectoral_support = row.get("跨部门支持", "")
                f_support_msg = row.get("支持内容", "")
                f_contact_parents = row.get("联系家长", "")
                f_province_system = row.get("省厅系统填报", "")
                f_graduate_form = row.get("毕业生登记表填报", "")
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_background_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_background_info_id = request.json.get("background_info_id", str())
            query = self.session.query(CdcBackgroundInfo).filter(CdcBackgroundInfo.f_sid == f_sid)
            obj = query.first()
            resume_query = self.session.query(CdcResumeInfo).filter(CdcResumeInfo.f_sid == f_sid)
            resume_objs = resume_query.all()
            resume_ids = [resume_obj.id for resume_obj in resume_objs]
            res = dict()
            res["uid"] = f_uid
            res["sid"] = str(obj.f_sid)
            res["record_id"] = str(f_record_id)
            res["background_info_id"] = str(obj.id)
            res["resume_id"] = resume_ids
            res["graduate_plan"] = str(obj.f_graduate_plan)
            res["chinese_lavel"] = str(obj.f_chinese_level)
            res["intend_employment_area"] = str(obj.f_intend_employment_area)
            res["intend_employment_industry"] = str(obj.f_intend_employment_industry)
            res["intend_employment_position"] = str(obj.f_intend_employment_position)
            res["intend_study_area"] = str(obj.f_intend_study_area)
            res["intend_study_school"] = str(obj.f_intend_study_school)
            res["intend_study_major"] = str(obj.f_intend_study_major)
            res["gre_gmat"] = str(obj.f_gre_gmat)
            res["ielts_toefl"] = str(obj.f_ielts_toefl)
            res["internship_count"] = str(self.session.query(CdcInternshipInfo).filter(CdcInternshipInfo.f_sid == f_sid).count())
            res["consult_count"] = str(0)
            res["activity_count"] = str(self.session.query(CdcActivityInfo).filter(CdcActivityInfo.f_sid == f_sid).count())
            res["resume_id"] = resume_ids
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_background_info_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_background_info_id = request.json.get("background_info_id", str())
            f_graduate_plan = request.json.get("graduate_plan", str())
            f_gre_gmat = request.json.get("gre_gmat", str())
            f_ielts_toefl = request.json.get("ielts_toefl", str())
            f_intend_employment_area = request.json.get("intend_employment_area", str())
            f_intend_employment_industry = request.json.get("intend_employment_industry", str())
            f_intend_employment_position = request.json.get("intend_employment_position", str())
            f_intend_study_area = request.json.get("intend_study_area", str())
            f_intend_study_major = request.json.get("intend_study_major", str())
            f_intend_study_school = request.json.get("intend_study_school", str())
            query = self.session.query(CdcBackgroundInfo).filter(CdcBackgroundInfo.f_sid == f_sid, CdcBackgroundInfo.id == f_background_info_id)
            obj = query.first()
            obj.f_graduate_plan = f_graduate_plan
            obj.f_gre_gmat = f_gre_gmat
            obj.f_ielts_toefl = f_ielts_toefl
            obj.f_intend_employment_area = f_intend_employment_area
            obj.f_intend_employment_industry = f_intend_employment_industry
            obj.f_intend_employment_position = f_intend_employment_position
            obj.f_intend_study_area = f_intend_study_area
            obj.f_intend_study_major = f_intend_study_major
            obj.f_intend_study_school = f_intend_study_school
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            query = self.session.query(CdcActivityInfo).filter(CdcActivityInfo.f_sid == f_sid)
            total = query.count()
            query = query.offset((int(f_page) - 1) * int(f_limit)).limit(int(f_limit))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "uid": f_uid,
                    "sid": str(obj.f_sid),
                    "record_id": f_record_id,
                    "activity_info_id": str(obj.id),
                    "activity_time": str(int(obj.f_activity_time.timestamp())) if obj.f_activity_time else "",
                    "activity_type": str(obj.f_activity_type),
                    "activity_name": str(obj.f_activity_name),
                    "remark": str(obj.f_remark),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_import(self):
        try:
            f_uid = request.form.get("uid", str())
            f_sid = request.form.get("sid", str())
            f_record_id = request.form.get("record_id", str())
            if "file" not in request.files:
                return jsonify({"code": 400, "msg": "未上传文件", "data": dict()})
            file = request.files["file"]
            if file.filename == "" or not file.filename.endswith(".xlsx"):
                return jsonify({"code": 400, "msg": "请选择有效的 XLSX 文件", "data": dict()})
            df = pd.read_excel(file)
            for index, row in df.iterrows():
                if index < 1:
                    continue
                f_sid = row.get("学号", "")
                f_name = row.get("姓名", "")
                f_major = row.get("专业", "")
                f_gender = row.get("性别", "")
                f_activity_type = row.get("活动类型", "")
                f_activity_name = row.get("活动名称", "")
                f_activity_time = row.get("活动时间", "")
                f_remark = row.get("备注", "")
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_cell_create(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_activity_time = request.json.get("activity_time", str())
            f_activity_type = request.json.get("activity_type", str())
            f_activity_name = request.json.get("activity_name", str())
            f_remark = request.json.get("remark", str())
            s_obj = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid).first()
            obj = CdcActivityInfo(
                f_sid=f_sid,
                f_activity_time=func.from_unixtime(f_activity_time),
                f_activity_type=f_activity_type,
                f_activity_name=f_activity_name,
                f_remark=f_remark,
                f_sid_id=s_obj.id
            )
            self.session.add(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "activity_info_id": str(obj.id),
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_cell_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_activity_info_id = request.json.get("activity_info_id", str())
            query = self.session.query(CdcActivityInfo).filter(CdcActivityInfo.f_sid == f_sid)
            obj = query.first()
            res = dict()
            res["uid"] = f_uid
            res["sid"] = str(obj.f_sid)
            res["record_id"] = str(f_record_id)
            res["activity_info_id"] = str(obj.id)
            res["activity_time"] = str(int(obj.f_activity_time.timestamp())) if obj.f_activity_time else ""
            res["activity_type"] = str(obj.f_activity_type)
            res["activity_name"] = str(obj.f_activity_name)
            res["remark"] = str(obj.f_remark)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_cell_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_activity_info_id = request.json.get("activity_info_id", str())
            f_activity_time = request.json.get("activity_time", str())
            f_activity_type = request.json.get("activity_type", str())
            f_activity_name = request.json.get("activity_name", str())
            f_remark = request.json.get("remark", str())
            query = self.session.query(CdcActivityInfo).filter(CdcActivityInfo.f_sid == f_sid, CdcActivityInfo.id == f_activity_info_id)
            obj = query.first()
            obj.f_activity_time = func.from_unixtime(f_activity_time)
            obj.f_activity_type = f_activity_type
            obj.f_activity_name = f_activity_name
            obj.f_remark = f_remark
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_activity_info_cell_delete(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_activity_info_id = request.json.get("activity_info_id", str())
            query = self.session.query(CdcActivityInfo).filter(CdcActivityInfo.f_sid == f_sid, CdcActivityInfo.id == f_activity_info_id)
            obj = query.first()
            self.session.delete(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            query = self.session.query(CdcInternshipInfo).filter(CdcInternshipInfo.f_sid == f_sid)
            total = query.count()
            query = query.offset((int(f_page) - 1) * int(f_limit)).limit(int(f_limit))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "uid": f_uid,
                    "sid": str(obj.f_sid),
                    "record_id": str(f_record_id),
                    "internship_info_id": str(obj.id),
                    "start_time": str(int(obj.f_start_time.timestamp())) if obj.f_start_time else "",
                    "end_time": str(int(obj.f_end_time.timestamp())) if obj.f_end_time else "",
                    "internship_company": str(obj.f_company),
                    "internship_position": str(obj.f_position),
                    "internship_location": str(obj.f_location),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_import(self):
        try:
            f_uid = request.form.get("uid", str())
            f_sid = request.form.get("sid", str())
            f_record_id = request.form.get("record_id", str())
            if "file" not in request.files:
                return jsonify({"code": 400, "msg": "未上传文件", "data": dict()})
            file = request.files["file"]
            if file.filename == "" or not file.filename.endswith(".xlsx"):
                return jsonify({"code": 400, "msg": "请选择有效的 XLSX 文件", "data": dict()})
            df = pd.read_excel(file)
            for index, row in df.iterrows():
                if index < 1:
                    continue
                f_sid = row.get("学号", "")
                f_name = row.get("姓名", "")
                f_major = row.get("专业", "")
                f_gpa = row.get("cGPA", "")
                f_gender = row.get("性别", "")
                f_internship_company = row.get("实习单位", "")
                f_internship_position = row.get("实习岗位", "")
                f_internship_location = row.get("实习地点", "")
                f_start_time = row.get("开始时间", "")
                f_end_time = row.get("结束时间", "")
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_cell_create(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_start_time = request.json.get("start_time", datetime.datetime.now())
            f_end_time = request.json.get("start_time", datetime.datetime.now())
            f_company = request.json.get("company", str())
            f_position = request.json.get("position", str())
            f_location = request.json.get("location", str())

            s_obj = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid).first()
            obj = CdcInternshipInfo(
                f_sid = f_sid,
                f_start_time = func.from_unixtime(f_start_time),
                f_end_time = func.from_unixtime(f_end_time),
                f_company = f_company,
                f_position = f_position,
                f_location = f_location,
                f_sid_id = s_obj.id
            )
            self.session.add(obj)
            self.session.commit()
            self.session.flush()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "offer_info_id": str(obj.id)
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_cell_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_internship_info_id = request.json.get("internship_info_id", str())
            query = self.session.query(CdcInternshipInfo).filter(CdcInternshipInfo.f_sid == f_sid)
            obj = query.first()
            res = dict()
            res["sid"] = str(obj.f_sid)
            res["internship_info_id"] = str(obj.id)
            res["start_time"] = str(int(obj.f_start_time.timestamp())) if obj.f_start_time else ""
            res["end_time"] = str(int(obj.f_start_time.timestamp())) if obj.f_end_time else ""
            res["internship_company"] = str(obj.f_company)
            res["internship_position"] = str(obj.f_position)
            res["internship_location"] = str(obj.f_location)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_cell_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_internship_info_id = request.json.get("internship_info_id", str())
            f_start_time = request.json.get("start_time", str())
            f_end_time = request.json.get("end_time", str())
            f_internship_company = request.json.get("internship_company", str())
            f_internship_position = request.json.get("internship_position", str())
            f_internship_location = request.json.get("internship_location", str())
            query = self.session.query(CdcInternshipInfo).filter(CdcInternshipInfo.f_sid == f_sid, CdcInternshipInfo.id == f_internship_info_id)
            obj = query.first()
            obj.f_start_time = func.from_unixtime(f_start_time)
            obj.f_end_time = func.from_unixtime(f_end_time)
            obj.f_company = f_internship_company
            obj.f_position = f_internship_position
            obj.f_location = f_internship_location
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_internship_info_cell_delete(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_internship_info_id = request.json.get("internship_info_id", str())
            query = self.session.query(CdcInternshipInfo).filter(CdcInternshipInfo.f_sid == f_sid, CdcInternshipInfo.id == f_internship_info_id)
            obj = query.first()
            self.session.delete(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid)
            total = query.count()
            query = query.offset((int(f_page) - 1) * int(f_limit)).limit(int(f_limit))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "sid": str(obj.f_sid),
                    "offer_info_id": str(obj.id),
                    "offer_type": str(obj.f_offer_type),
                    "location": str(obj.f_offer_area),
                    "company_college_name": str(obj.f_company_college_name),
                    "position_project_name": str(obj.f_position_project_name),
                    "project_type": str(obj.f_project_type),
                    "salary_month": str(obj.f_salary_month),
                    "salary_year": str(obj.f_salary_year),
                    "accept_status": str(obj.f_accept_status),
                    "remark": str(obj.f_remark),
                    "industry_name": str(),
                    "entrance_date": str(),
                    "offer_area": str(),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_cell_create(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_offer_type = request.json.get("offer_type", str())
            f_offer_area = request.json.get("offer_area", str())
            f_company_college_name = request.json.get("company_college_name", str())
            f_position_project_name = request.json.get("position_project_name", str())
            f_entrance_date = request.json.get("entrance_date", str())
            f_industry_name = request.json.get("industry_name", str())
            f_salary_month = request.json.get("salary_month", str())
            f_salary_year = request.json.get("salary_year", str())
            f_accept_status = request.json.get("accept_status", str())
            f_remark = request.json.get("remark", str())
            s_obj = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid).first()
            obj = CdcOfferInfo(
                f_sid=f_sid,
                f_offer_type=f_offer_type,
                f_offer_area=f_offer_area,
                f_company_college_name=f_company_college_name,
                f_position_project_name=f_position_project_name,
                f_entrance_date=f_entrance_date,
                f_industry_name=f_industry_name,
                f_salary_month=f_salary_month,
                f_salary_year=f_salary_year,
                f_accept_status=f_accept_status,
                f_remark=f_remark,
                f_sid_id=s_obj.id
            )
            self.session.add(obj)
            self.session.commit()
            self.session.flush()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "offer_info_id": str(obj.id)
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_cell_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_offer_info_id = request.json.get("offer_info_id", str())
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid)
            obj = query.first()
            res = dict()
            res["sid"] = str(obj.f_sid)
            res["offer_info_id"] = str(obj.id)
            res["offer_type"] = str(obj.f_offer_type)
            res["offer_area"] = str(obj.f_offer_area)
            res["college_name"] = str(obj.f_college_name)
            res["project_name"] = str(obj.f_project_name)
            res["project_type"] = str(obj.f_project_type)
            res["company_name"] = str(obj.f_company_name)
            res["position"] = str(obj.f_position)
            res["salary_month"] = str(obj.f_month_salary)
            res["salary_year"] = str(obj.f_year_salary)
            res["entrance_date"] = str(int(obj.f_entrance_date.timestamp())) if obj.f_entrance_date else ""
            res["entrance_year"] = str(obj.f_entrance_year)
            res["accept_status"] = str(obj.f_accept_status)
            res["remark"] = str(obj.f_remark)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_cell_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_offer_info_id = request.json.get("offer_info_id", str())
            f_offer_type = request.json.get("offer_type", str())
            f_offer_area = request.json.get("offer_area", str())
            f_college_name = request.json.get("college_name", str())
            f_project_name = request.json.get("project_name", str())
            f_project_type = request.json.get("project_type", str())
            f_company_name = request.json.get("company_name", str())
            f_position = request.json.get("position", str())
            f_salary_month = request.json.get("salary_month", str())
            f_salary_year = request.json.get("salary_year", str())
            f_entrance_date = request.json.get("entrance_date", str())
            f_entrance_year = request.json.get("entrance_year", str())
            f_accept_status = request.json.get("accept_status", str())
            f_remark = request.json.get("remark", str())
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid, CdcOfferInfo.id == f_offer_info_id)
            obj = query.first()
            obj.f_offer_type = f_offer_type
            obj.f_offer_area = f_offer_area
            obj.f_college_name = f_college_name
            obj.f_project_name = f_project_name
            obj.f_project_type = f_project_type
            obj.f_company_name = f_company_name
            obj.f_position = f_position
            obj.f_salary_month = f_salary_month
            obj.f_salary_year = f_salary_year
            obj.f_entrance_date = func.from_unixtime(f_entrance_date)
            obj.f_entrance_year = f_entrance_year
            obj.f_accept_status = f_accept_status
            obj.f_remark = f_remark
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_cell_delete(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_offer_info_id = request.json.get("offer_info_id", str())
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid, CdcOfferInfo.id == f_offer_info_id)
            obj = query.first()
            self.session.delete(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_download(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            query = self.session.query(CdcOfferInfo).filter(CdcOfferInfo.f_sid == f_sid)
            objs = query.all()
            res = list()
            seq = 0
            for obj in objs:
                seq += 1
                res.append({
                    "seq": str(seq),
                    "sid": str(obj.f_sid),
                    "offer_type": str(obj.f_offer_type),
                    "offer_area": str(obj.f_offer_area),
                    "college_name": str(obj.f_college_name),
                    "project_name": str(obj.f_project_name),
                    "project_type": str(obj.f_project_type),
                    "company_name": str(obj.f_company_name),
                    "position": str(obj.f_position),
                    "month_salary": str(obj.f_month_salary),
                    "year_salary": str(obj.f_year_salary),
                    "entrance_date": str(int(obj.f_entrance_date.timestamp())) if obj.f_entrance_date else "",
                    "entrance_year": str(obj.f_entrance_year),
                    "accept_status": str(obj.f_accept_status)
                })
            df = pd.DataFrame(res)
            output = BytesIO()
            with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
                df.to_excel(writer, sheet_name="Download", index=False)
            output.seek(0)
            return send_file(output, as_attachment=True, mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", download_name="Export.xlsx")
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_school_fuzzy(self):
        try:
            f_query_key = request.json.get("query_key", str())
            query = self.session.query(CdcSchoolProgramArea).filter(CdcSchoolProgramArea.f_school.ilike(f'%{f_query_key}%'))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_school)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res)),
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_program_fuzzy(self):
        try:
            f_query_key = request.json.get("query_key", str())
            query = self.session.query(CdcSchoolProgramArea).filter(CdcSchoolProgramArea.f_program.ilike(f'%{f_query_key}%'))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_program)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res)),
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_offer_info_area_fuzzy(self):
        try:
            f_query_key = request.json.get("query_key", str())
            query = self.session.query(CdcSchoolProgramArea).filter(CdcSchoolProgramArea.f_area.ilike(f'%{f_query_key}%'))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_area)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res)),
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_key_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_key_info_id = request.json.get("key_info_id", str())
            res = dict()
            query = self.session.query(CdcKeyInfo).filter(CdcKeyInfo.f_sid == f_sid)
            obj = query.first()
            res["sid"] = str(obj.f_sid)
            res["key_info_id"] = str(obj.id)
            res["apecial_attention"] = str(obj.f_apecial_attention)
            res["difficulty_type"] = str(obj.f_difficulty_type)
            res["support_need"] = str(obj.f_support_need)
            res["support_info"] = str(obj.f_support_info)
            res["parents_contacted"] = str(obj.f_parents_contacted)

            query = self.session.query(CdcGraduateInfo).filter(CdcGraduateInfo.f_sid == f_sid)
            obj = query.first()
            res["province_system_report"] = str(obj.f_province_system_report)
            res["graduate_registe_report"] = str(obj.f_graduate_registe_report)

            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_key_info_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_key_info_id = request.json.get("key_info_id", str())
            f_apecial_attention = request.json.get("special_attention", str())
            f_difficulty_type = request.json.get("difficulty_type", str())
            f_support_need = request.json.get("support_need", str())
            f_support_info = request.json.get("support_info", str())
            f_parents_contacted = request.json.get("parents_contacted", str())

            query = self.session.query(CdcKeyInfo).filter(CdcKeyInfo.f_sid == f_sid)
            obj = query.first()
            obj.f_apecial_attention = f_apecial_attention
            obj.f_difficulty_type = f_difficulty_type
            obj.f_support_need = f_support_need
            obj.f_support_info = f_support_info
            obj.f_parents_contacted = f_parents_contacted
            self.session.commit()

            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_graduate_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_graduate_info_id = request.json.get("graduate_info_id", str())
            query = self.session.query(CdcGraduateInfo).filter(CdcGraduateInfo.f_sid == f_sid)
            obj = query.first()
            res = dict()
            res["sid"] = str(obj.f_sid)
            res["graduate_info_id"] = str(obj.id)
            res["province_system_report"] = str(obj.f_province_system_report)
            res["graduate_registe_report"] = str(obj.f_graduate_registe_report)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_graduate_info_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_graduate_info_id = request.json.get("graduate_info_id", str())
            f_province_system_report = request.json.get("province_system_report", str())
            f_graduate_registe_report = request.json.get("graduate_registe_report", str())
            query = self.session.query(CdcGraduateInfo).filter(CdcGraduateInfo.f_sid == f_sid, CdcGraduateInfo.id == f_graduate_info_id)
            obj = query.first()
            obj.f_province_system_report = f_province_system_report
            obj.f_graduate_registe_report = f_graduate_registe_report
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_recommend_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_cgpa = request.json.get("cgpa", str())
            f_area = request.json.get("area", str())
            f_major = request.json.get("major", str())
            f_program = request.json.get("program", str())
            # TODO: 选校推荐的逻辑
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": [
                        "清华大学",
                        "北京大学",
                        "哈尔滨工业大学",
                        "西北工业大学"
                    ],
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})
    
    def detail_recommend_info_area_search(self):
        try:
            f_uid = request.json.get("uid", str())
            query = self.session.query(CdcBoxArea)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_recommend_info_major_search(self):
        try:
            f_uid = request.json.get("uid", str())
            query = self.session.query(CdcBoxMajor)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_recommend_info_program_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_query_key = request.json.get("query_key", str())
            query = self.session.query(CdcSchoolProgramArea).filter(CdcSchoolProgramArea.f_program.ilike(f'%{f_query_key}%'))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_program)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_daily_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_page = request.json.get("page", str())
            f_limit = request.json.get("limit", str())
            query = self.session.query(CdcDailyInfo).filter(CdcDailyInfo.f_sid == f_sid).order_by(desc(CdcDailyInfo.f_time))
            total = query.count()
            query = query.offset((int(f_page) - 1) * int(f_limit)).limit(int(f_limit))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "sid": str(obj.f_sid),
                    "daily_info_id": str(obj.id),
                    "daily_record_owner": str(obj.f_owner),
                    "daily_record_type": str(obj.f_type),
                    "daily_record_time": str(int(obj.f_time.timestamp())) if obj.f_time else "",
                    "daily_record_detail": str(obj.f_detail)
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_daily_info_cell_create(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_record_type = request.json.get("record_type", str())
            f_record_time = request.json.get("record_time", str())
            f_record_detail = request.json.get("record_detail", str())
            s_obj = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid).first()
            f_owner = self.session.query(CdcUserInfo).filter(CdcUserInfo.id == f_uid).first().f_display_name
            obj = CdcDailyInfo(
                f_sid=f_sid,
                f_type=f_record_type,
                f_time=func.from_unixtime(f_record_time),
                f_detail=f_record_detail,
                f_owner=f_owner,
                f_sid_id=s_obj.id
            )
            self.session.add(obj)
            self.session.commit()
            self.session.flush()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "daily_info_id": str(obj.id)
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_daily_info_cell_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_daily_info_id = request.json.get("daily_info_id", str())
            query = self.session.query(CdcDailyInfo).filter(CdcDailyInfo.f_sid == f_sid, CdcDailyInfo.id == f_daily_info_id)
            obj = query.first()
            res = dict()
            res["sid"] = str(obj.f_sid)
            res["daily_info_id"] = str(obj.id)
            res["daily_record_owner"] = str(obj.f_owner)
            res["daily_record_type"] = str(obj.f_type)
            res["daily_record_time"] = str(int(obj.f_time.timestamp())) if obj.f_time else ""
            res["daily_record_detail"] = str(obj.f_detail)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_daily_info_cell_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_daily_info_id = request.json.get("daily_info_id", str())
            f_record_owner = request.json.get("record_name", str())
            f_record_type = request.json.get("record_type", str())
            f_record_time = request.json.get("record_time", str())
            f_record_detail = request.json.get("record_detail", str())
            query = self.session.query(CdcDailyInfo).filter(CdcDailyInfo.f_sid == f_sid, CdcDailyInfo.id == f_daily_info_id)
            obj = query.first()
            obj.f_owner = f_record_owner
            obj.f_type = f_record_type
            obj.f_time = func.from_unixtime(f_record_time)
            obj.f_detail = f_record_detail
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_daily_info_cell_delete(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_daily_info_id = request.json.get("daily_info_id", str())
            query = self.session.query(CdcDailyInfo).filter(CdcDailyInfo.f_sid == f_sid, CdcDailyInfo.id == f_daily_info_id)
            obj = query.first()
            self.session.delete(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_graduate_plan_search(self):
        try:
            query = self.session.query(CdcBoxGraduatePlan)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_offer_type_search(self):
        try:
            query = self.session.query(CdcBoxOfferType)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_chinese_level_search(self):
        try:
            query = self.session.query(CdcBoxChineseLevel)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_project_type_search(self):
        try:
            query = self.session.query(CdcBoxProjectType)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_entrance_year_search(self):
        try:
            query = self.session.query(CdcBoxEntranceYear)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_offer_status_search(self):
        try:
            query = self.session.query(CdcBoxOfferState)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_difficulty_type_search(self):
        try:
            query = self.session.query(CdcBoxDifficultyType)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_apecial_attention_search(self):
        try:
            query = self.session.query(CdcBoxApecialAttention)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_parents_contacted_search(self):
        try:
            query = self.session.query(CdcBoxParentsContacted)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_province_system_report_search(self):
        try:
            query = self.session.query(CdcBoxProvinceSystemReport)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_graduate_registe_report_search(self):
        try:
            query = self.session.query(CdcBoxGraduateRegisteReport)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_recommend_area_search(self):
        try:
            # TODO: 待实现
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": ["中国", "美国", "英国", "日本", "法国", "德国", "韩国", "新加坡", "马来西亚", "比利时", "荷兰", "西班牙", "意大利", "澳大利亚", "新西兰", "印度", "泰国", "俄罗斯", "土耳其", "沙特阿拉伯", "阿联酋", "伊朗", "埃及", "越南", "菲律宾", "印度尼西亚", "巴基斯坦", "缅甸", "柬埔寨", ]
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})
    
    def box_record_type_search(self):
        try:
            query = self.session.query(CdcBoxRecordType)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res))
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_enrollment_type_search(self):
        try:
            query = self.session.query(CdcBoxEnrollmentType)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res))
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_enrollment_status_search(self):
        try:
            query = self.session.query(CdcBoxEnrollmentStatus)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res))
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def box_advisor_search(self):
        try:
            query = self.session.query(CdcBoxAdvisor)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append(obj.f_value)
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": list(set(res))
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def access_list_search(self):
        try:
            query = self.session.query(CdcAccessInfo)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "access_id": str(obj.f_access_id),
                    "access_name": str(obj.f_access_name),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res,
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def access_user_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_page = request.json.get("page", 1)
            f_limit = request.json.get("limit", 10)
            query = self.session.query(CdcUserInfo).filter(CdcUserInfo.f_access_id != "1").order_by(CdcUserInfo.id)
            total = query.count()
            query = query.offset((int(f_page) - 1) * int(f_limit)).limit(int(f_limit))
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "user_id": str(obj.id),
                    "access_id": str(obj.f_access_id),
                    "user_name": str(obj.f_username),
                    "access_name": str(obj.f_access_name),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "total": total,
                        "detail": res
                    },
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def access_user_info_update(self):
        try:
            f_uid = request.json.get("uid", str())
            f_user_id = request.json.get("user_id", str())
            f_access_id = request.json.get("access_id", str())
            f_access_name = request.json.get("access_name", str())
            query = self.session.query(CdcUserInfo).filter(CdcUserInfo.id == f_user_id)
            obj = query.first()
            obj.f_access_id = f_access_id
            obj.f_access_name = f_access_name
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {},
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_resume_info_upload(self):
        try:
            f_uid = request.form.get("uid", str())
            f_sid = request.form.get("sid", str())
            f_record_id = request.form.get("record_id", str())
            if "file" not in request.files:
                return jsonify({"code": 400, "msg": "未上传文件", "data": {}})
            file = request.files["file"]
            if file.filename == "":
                return jsonify({"code": 400, "msg": "未选择文件", "data": {}})
            file_path = "/".join([self.resume_path, f_sid, file.filename])
            if not os.path.exists(os.path.dirname(file_path)):
                os.makedirs(os.path.dirname(file_path))
            file.save(file_path)
            s_obj = self.session.query(CdcBaseInfo).filter(CdcBaseInfo.f_sid == f_sid).first()
            obj = CdcResumeInfo(
                f_sid=f_sid,
                f_resume_name=file.filename,
                f_resume_path=file_path,
                f_resume_data=b"N/A",
                f_sid_id=s_obj.id
            )
            self.session.add(obj)
            self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": {
                        "file_name": file.filename
                    }
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_resume_info_download(self):
        try:
            resume_id = request.args.get("resume_id", str())
            query = self.session.query(CdcResumeInfo).filter(CdcResumeInfo.id == resume_id)
            obj = query.first()
            f_resume_path = obj.f_resume_path
            file_directory = os.path.dirname(f_resume_path)
            file_name = os.path.basename(f_resume_path)
            return send_from_directory(
                file_directory,
                file_name,
                as_attachment=True
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_resume_info_delete(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            f_resume_id = request.json.get("resume_id", str())
            query = self.session.query(CdcResumeInfo).filter(CdcResumeInfo.f_sid == f_sid, f_resume_id == f_resume_id)
            obj = query.first()
            if obj is not None:
                file_path = obj.f_resume_path
                os.remove(file_path)
                self.session.delete(obj)
                self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": dict()
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def export_options_search(self):
        try:
            res = list()
            query = self.session.query(CdcBoxExportOptions)
            objs = query.all()
            for obj in objs:
                res.append({
                    "export_id": str(obj.id),
                    "export_desc": str(obj.f_value)
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def export_search(self):
        try:
            f_export_id = request.json.get("export_id", str())
            f_export_desc = request.json.get("export_desc", str())
            file_name = ".".join([f_export_desc, "xlsx"])
            if f_export_id == "1":
                query = self.session.query(
                    CdcBaseInfo, CdcBackgroundInfo, CdcKeyInfo, CdcGraduateInfo
                ).join(
                    CdcBackgroundInfo, CdcBackgroundInfo.f_sid == CdcBaseInfo.f_sid
                ).join(
                    CdcKeyInfo, CdcKeyInfo.f_sid == CdcBaseInfo.f_sid
                ).join(
                    CdcGraduateInfo, CdcGraduateInfo.f_sid == CdcBaseInfo.f_sid
                )
                objs = query.all()
                res = list()
                for obj in objs:
                    res.append({
                        "学号": str(obj.CdcBaseInfo.f_sid),
                        "姓名": str(obj.CdcBaseInfo.f_name),
                        "性别": str(obj.CdcBaseInfo.f_grade),
                        "书院": str(obj.CdcBaseInfo.f_academy),
                        "专业名称": str(obj.CdcBaseInfo.f_major),
                        "综合GPA": str(obj.CdcBaseInfo.f_gpa),
                        "年级": str(obj.CdcBaseInfo.f_grade),
                        "预毕业学期": str(obj.CdcBaseInfo.f_graduation_pre_term),
                        "毕业年份": str(obj.CdcBaseInfo.f_graduation_pre_year),
                        "联系方式": str(obj.CdcBaseInfo.f_phone),
                        "邮箱": str(obj.CdcBaseInfo.f_email),
                        "学籍状态": str(obj.CdcBaseInfo.f_status),
                        "招生类型": str(obj.CdcBaseInfo.f_enrollment_type),
                        "修分情况": str(obj.CdcBaseInfo.f_credit_status),
                        "预警信息": str(obj.CdcBaseInfo.f_warn_info),
                        "顾问": str(obj.CdcBaseInfo.f_advisor),
                        "毕业计划": str(obj.CdcBackgroundInfo.f_graduate_plan),
                        "意向就业地区": str(obj.CdcBackgroundInfo.f_intend_employment_area),
                        "意向就业行业": str(obj.CdcBackgroundInfo.f_intend_employment_industry),
                        "意向就业岗位": str(obj.CdcBackgroundInfo.f_intend_employment_position),
                        "意向升学地区": str(obj.CdcBackgroundInfo.f_intend_study_area),
                        "意向升学院校": str(obj.CdcBackgroundInfo.f_intend_study_school),
                        "意向升学领域": str(obj.CdcBackgroundInfo.f_intend_study_major),
                        "GRE/GMAT": str(obj.CdcBackgroundInfo.f_gre_gmat),
                        "雅思/托福": str(obj.CdcBackgroundInfo.f_ielts_toefl),
                        "特需生": str(obj.CdcKeyInfo.f_apecial_attention),
                        "困难类型": str(obj.CdcKeyInfo.f_difficulty_type),
                        "跨部门支持": str(obj.CdcKeyInfo.f_support_need),
                        "支持内容": str(obj.CdcKeyInfo.f_support_info),
                        "联系家长": str(obj.CdcKeyInfo.f_parents_contacted),
                        "省厅系统填报": str(obj.CdcGraduateInfo.f_province_system_report),
                        "毕业生登记表填报": str(obj.CdcGraduateInfo.f_graduate_registe_report)
                    })
                df = pd.DataFrame(res)
                output = BytesIO()
                with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
                    df.to_excel(writer, sheet_name='Export', index=False)
                output.seek(0)

            if f_export_id == "2":
                query = self.session.query(
                    CdcBaseInfo, CdcOfferInfo
                ).join(
                    CdcOfferInfo, CdcOfferInfo.f_sid == CdcBaseInfo.f_sid
                )
                objs = query.all()
                res = list()
                for obj in objs:
                    res.append({
                        "学号": str(obj.CdcBaseInfo.f_sid),
                        "姓名": str(obj.CdcBaseInfo.f_name), 
                        "性别": str(obj.CdcBaseInfo.f_gender),
                        "专业": str(obj.CdcBaseInfo.f_major),
                        "cGPA": str(obj.CdcBaseInfo.f_gpa),
                        "毕业年份": str(int(obj.CdcBaseInfo.f_graduation_pre_year)) if obj.CdcBaseInfo.f_graduation_pre_year else '',
                        "项目类型": str(obj.CdcOfferInfo.f_project_type),
                        "Offer类型": str(obj.CdcOfferInfo.f_offer_type),
                        "企业/学校": str(obj.CdcOfferInfo.f_company_college_name),
                        "职位/项目": str(obj.CdcOfferInfo.f_position_project_name),
                        "地点": str(obj.CdcOfferInfo.f_location),
                        "月薪": str(obj.CdcOfferInfo.f_salary_month),
                        "年薪": str(obj.CdcOfferInfo.f_salary_year),
                        "接受情况": str(obj.CdcOfferInfo.f_accept_status),
                        "备注": str(obj.CdcOfferInfo.f_remark)
                    })
                df = pd.DataFrame(res)
                output = BytesIO()
                with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
                    df.to_excel(writer, sheet_name='Export', index=False)
                output.seek(0)
            if f_export_id == "3":
                query = self.session.query(
                    CdcBaseInfo, CdcInternshipInfo
                ).join(
                    CdcInternshipInfo, CdcInternshipInfo.f_sid == CdcBaseInfo.f_sid
                )
                objs = query.all()
                res = list()
                for obj in objs:
                    res.append({
                        "学号": str(obj.CdcBaseInfo.f_sid),
                        "姓名": str(obj.CdcBaseInfo.f_name),
                        "专业": str(obj.CdcBaseInfo.f_major),
                        "cGPA": str(obj.CdcBaseInfo.f_gpa),
                        "性别": str(obj.CdcBaseInfo.f_gender),
                        "实习单位": str(obj.CdcInternshipInfo.f_company),
                        "实习岗位": str(obj.CdcInternshipInfo.f_position),
                        "实习地点": str(obj.CdcInternshipInfo.f_location),
                        "开始时间": str(datetime.fromtimestamp(obj.CdcInternshipInfo.f_start_time).strftime("%Y-%m")),
                        "结束时间": str(datetime.fromtimestamp(obj.CdcInternshipInfo.f_end_time).strftime("%Y-%m")),
                    })
                df = pd.DataFrame(res)
                output = BytesIO()
                with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
                    df.to_excel(writer, sheet_name='Export', index=False)
                output.seek(0)
            if f_export_id == "4":
                pass

            return send_file(
                output, 
                as_attachment=True, 
                mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
                download_name=file_name
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def import_options_search(self):
        try:
            res = list()
            query = self.session.query(CdcBoxImportOptions)
            objs = query.all()
            for obj in objs:
                res.append({
                    "import_id": str(obj.id),
                    "import_desc": str(obj.f_value)
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})
    
    def import_file_upload(self):
        try:
            f_uid = request.form.get("uid", str())
            f_import_id = request.form.get("import_id", str())
            f_import_desc = request.form.get("import_desc", str())
            if "file" not in request.files:
                return jsonify({"code": 400, "msg": "未上传文件", "data": {}})
            file = request.files["file"]
            if file.filename == "":
                return jsonify({"code": 400, "msg": "未选择文件", "data": {}})
            if not file.filename.endswith(".xlsx"):
                return jsonify({"code": 400, "msg": "仅支持.xlsx文件", "data": {}})
            df = pd.read_excel(file)
            if f_import_id == "1" and f_import_desc == "学生基本信息":
                for _, row in df.iterrows():
                    base_dict = {
                        "f_sid": row["学号"],
                        "f_name": row["姓名"],
                        "f_major": row["专业名称"],
                        "f_grade": row["年级"],
                        "f_phone": row["联系方式"],
                        "f_email": row["邮箱"],
                        "f_warn_info": row["预警信息"],
                        "f_gender": row["性别"],
                        "f_academy": row["书院"],
                        "f_gpa": row["综合GPA"],
                        "f_status": row["学籍状态"],
                        "f_enrollment_type": row["招生类型"],
                        "f_credit_status": row["修分情况"],
                        "f_advisor": row["顾问"],
                        "f_graduation_pre_term": row["预毕业学期"],
                        "f_graduation_pre_year": datetime.datetime.strptime(str(row["毕业年份"]), "%Y"),
                    }
                    background_dict = {
                        "f_sid": row["学号"],
                        "f_graduate_plan": row["毕业计划"],
                        "f_chinese_level": "N/A",
                        "f_intend_employment_area": row["意向就业地区"],
                        "f_intend_employment_industry": row["意向就业行业"],
                        "f_intend_employment_position": row["意向就业岗位"],
                        "f_intend_study_area": row["意向升学地区"],
                        "f_intend_study_school": row["意向升学院校"],
                        "f_intend_study_major": row["意向升学领域"],
                        "f_gre_gmat": row["GRE/GMAT"],
                        "f_ielts_toefl": row["雅思/托福"]
                    }
                    key_dict = {
                        "f_sid": row["学号"],
                        "f_apecial_attention": row["特需生"],
                        "f_difficulty_type": row["困难类型"],
                        "f_support_need": row["跨部门支持"],
                        "f_support_info": row["支持内容"],
                        "f_parents_contacted": row["联系家长"]
                    }
                    graduate_dict = {
                        "f_sid": row["学号"],
                        "f_province_system_report": row["省厅系统填报"],
                        "f_graduate_registe_report": row["毕业生登记表填报"]
                    }
                    base_query = self.session.query(CdcBaseInfo).filter_by(f_sid=base_dict["f_sid"])
                    background_query = self.session.query(CdcBackgroundInfo).filter_by(f_sid=background_dict["f_sid"])
                    key_query = self.session.query(CdcKeyInfo).filter_by(f_sid=key_dict["f_sid"])
                    graduate_query = self.session.query(CdcGraduateInfo).filter_by(f_sid=graduate_dict["f_sid"])
                    base_obj = base_query.first()
                    background_obj = background_query.first()
                    key_obj = key_query.first()
                    graduate_obj = graduate_query.first()
                    if not base_obj:
                        new_base_obj = CdcBaseInfo(**base_dict)
                        self.session.add(new_base_obj)
                        self.session.flush() 
                        self.session.commit()
                        f_sid_id = new_base_obj.id
                        background_dict["f_sid_id"] = f_sid_id
                        key_dict["f_sid_id"] = f_sid_id
                        graduate_dict["f_sid_id"] = f_sid_id
                        new_background_obj = CdcBackgroundInfo(**background_dict)
                        self.session.add(new_background_obj)
                        self.session.commit()
                        new_key_obj = CdcKeyInfo(**key_dict)
                        self.session.add(new_key_obj)
                        self.session.commit()
                        new_graduate_obj = CdcGraduateInfo(**graduate_dict)
                        self.session.add(new_graduate_obj)
                        self.session.commit()
                    else:
                        for k, v in base_dict.items():
                            if hasattr(base_obj, k) and k not in ["f_sid", "f_sid_id"]:
                                setattr(base_obj, k, v)
                        for k, v in background_dict.items():
                            if hasattr(background_obj, k) and k not in ["f_sid", "f_sid_id"]:
                                setattr(background_obj, k, v)
                        for k, v in key_dict.items():
                            if hasattr(key_obj, k) and k not in ["f_sid", "f_sid_id"]:
                                setattr(key_obj, k, v)
                        for k, v in graduate_dict.items():
                            if hasattr(graduate_obj, k) and k not in ["f_sid", "f_sid_id"]:
                                setattr(graduate_obj, k, v)
            elif f_import_id == "2" and f_import_desc == "学生Offer信息":
                for _, row in df.iterrows():
                    offer_dict = {
                        "f_sid": row["学号"],
                        "f_offer_type": row["Offer类型"],
                        "f_offer_area": row["地点"],
                        "f_company_college_name": row["企业/学校"],
                        "f_position_project_name": row["职位/项目"],
                        "f_salary_month": row["基本工资(人民币)"],
                        "f_salary_year": row["年薪(税前，含奖金)"],
                        "f_accept_status": row["接受情况"],
                        "f_project_type": row["项目类型"],
                        "f_remark": row["备注"],
                    }
                    base_query = self.session.query(CdcBaseInfo).filter_by(f_sid=offer_dict["f_sid"])
                    base_obj = base_query.first()
                    offer_query = self.session.query(CdcOfferInfo).filter_by(f_sid=offer_dict["f_sid"])
                    offer_objs = offer_query.all()
                    if not base_obj:
                        continue
                    for offer_obj in offer_objs:
                        self.session.delete(offer_obj)
                    offer_dict["f_sid_id"] = base_obj.id
                    new_offer_obj = CdcOfferInfo(**offer_dict)
                    self.session.add(new_offer_obj)
                    self.session.commit()
            elif f_import_id == "3" and f_import_desc == "学生实习信息":
                for _, row in df.iterrows():
                    internship_dict = {
                        "f_sid": row["学号"],
                        "f_start_time": datetime.datetime.strptime(str(row["开始时间"]), "%Y-%m-%d %H:%M:%S"),
                        "f_end_time": datetime.datetime.strptime(str(row["结束时间"]), "%Y-%m-%d %H:%M:%S"),
                        "f_company": row["实习单位"],
                        "f_position": row["实习岗位"],
                        "f_location": row["实习地点"],
                    }
                    base_query = self.session.query(CdcBaseInfo).filter_by(f_sid=internship_dict["f_sid"])
                    base_obj = base_query.first()
                    internship_query = self.session.query(CdcInternshipInfo).filter_by(f_sid=internship_dict["f_sid"])
                    internship_objs = internship_query.all()
                    if not base_obj:
                        continue
                    for internship_obj in internship_objs:
                        self.session.delete(internship_obj)
                    internship_dict["f_sid_id"] = base_obj.id
                    new_offer_obj = CdcInternshipInfo(**internship_dict)
                    self.session.add(new_offer_obj)
                    self.session.commit()
            elif f_import_id == "4" and f_import_desc == "学生活动信息":
                for _, row in df.iterrows():
                    activity_dict = {
                        "f_sid": row["学号"],
                        "f_activity_time": datetime.datetime.strptime(str(row["活动时间"]), "%Y-%m-%d %H:%M:%S"),
                        "f_activity_type": row["活动类型"],
                        "f_activity_name": row["活动名称"],
                        "f_remark": row["备注"],
                    }
                    base_query = self.session.query(CdcBaseInfo).filter_by(f_sid=activity_dict["f_sid"])
                    base_obj = base_query.first()
                    activity_query = self.session.query(CdcActivityInfo).filter_by(f_sid=activity_dict["f_sid"])
                    activity_objs = activity_query.all()
                    if not base_obj:
                        continue
                    for activity_obj in activity_objs:
                        self.session.delete(activity_obj)
                    activity_dict["f_sid_id"] = base_obj.id
                    new_offer_obj = CdcActivityInfo(**activity_dict)
                    self.session.add(new_offer_obj)
                    self.session.commit()
            elif f_import_id == "5" and f_import_desc == "学生日常信息":
                for _, row in df.iterrows():
                    user_query = self.session.query(CdcUserInfo).filter_by(id=f_uid)
                    user_obj = user_query.first()
                    user_name = user_obj.f_display_name
                    daily_dict = {
                        "f_sid": row["学号"],
                        "f_type": row["记录类型"],
                        "f_time": datetime.datetime.strptime(str(row["记录时间"]), "%Y-%m-%d %H:%M:%S"),
                        "f_detail": row["记录内容"],
                        "f_owner": user_name,
                    }
                    base_query = self.session.query(CdcBaseInfo).filter_by(f_sid=daily_dict["f_sid"])
                    base_obj = base_query.first()
                    if not base_obj:
                        continue
                    daily_dict["f_sid_id"] = base_obj.id
                    new_offer_obj = CdcDailyInfo(**daily_dict)
                    self.session.add(new_offer_obj)
                    self.session.commit()
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": []
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def import_template_search(self):
        try:
            f_import_id = request.json.get("import_id", str())
            f_import_desc = request.json.get("import_desc", str())
            file_name = ".".join([f_import_desc + "-模板", "xlsx"])
            file_directory = self.import_template_path
            return send_from_directory(
                file_directory,
                file_name,
                as_attachment=True
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})

    def detail_resume_info_search(self):
        try:
            f_uid = request.json.get("uid", str())
            f_sid = request.json.get("sid", str())
            f_record_id = request.json.get("record_id", str())
            query = self.session.query(CdcResumeInfo).filter(CdcResumeInfo.f_sid == f_sid)
            objs = query.all()
            res = list()
            for obj in objs:
                res.append({
                    "resume_id": str(obj.id),
                    "resume_name": str(obj.f_resume_name),
                })
            return jsonify(
                {
                    "code": 200,
                    "msg": "success",
                    "data": res
                }
            )
        except Exception as e:
            self.logger.error(f"[{request.request_id}] {e}")
            self.session.rollback()
            return jsonify({"code": 500, "msg": "服务器错误", "data": {}})
